package jdbclearn3;
/*
@Date:2025/3/12
*/

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Properties;

public class DruidDemo {
    public static void main(String[] args) throws Exception {
        final Properties properties = new Properties();
        final FileInputStream fileInputStream = new FileInputStream("src/jdbclearn3/jdbc.propertise");
        properties.load(fileInputStream);
//使用德鲁伊数据库连接池技术
        final DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        final Connection connection = dataSource.getConnection();
        System.out.println("connection = " + connection);
        String sql="select* from tb_user";
        final PreparedStatement preparedStatement = connection.prepareStatement(sql);
        final ResultSet resultSet = preparedStatement.executeQuery();
        ArrayList<Brand> brands = new ArrayList<>();
        while (resultSet.next()) {
            Brand brand = new Brand();
            brand.setId(resultSet.getInt("id"));
            brand.setUsername(resultSet.getString("username"));
            brand.setPassword(resultSet.getString("password"));
            brands.add(brand);
        }

        System.out.println("brands = " + brands);
    }
}

